/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uca.sisbec.actions.reportes;

import com.uca.sisbec.commons.HibernateAction;
import com.uca.sisbec.forms.reportes.ReporteNotasXCarreraForm;
import com.uca.sisbec.helpers.manto.CarreraHelper;
import com.uca.sisbec.helpers.reportes.ReporteNotasCarreraHelper;
import com.uca.sisbec.mapping.Becario;
import com.uca.sisbec.mapping.Carrera;
import com.uca.sisbec.mapping.CarreraXBecario;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Susy
 */
public class ReporteNotasCarreraAction extends HibernateAction {
    
    public ActionForward init(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (!isBecarioInSession(request)) return mapping.findForward("searchBecario");
        ReporteNotasXCarreraForm rnxc = (ReporteNotasXCarreraForm) form;
        Becario b = (Becario) request.getSession().getAttribute(_BECARIO);
        CarreraHelper carreraHelper = new CarreraHelper(getSession(request));
        List<Carrera> cxb = carreraHelper.obtenerCarreras(b);
        System.out.println(cxb.size());
        request.setAttribute("carrerasList",cxb);
        return mapping.findForward("success");
    }
    
    public ActionForward ConstruirReporteNotas(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ReporteNotasXCarreraForm rnxc = (ReporteNotasXCarreraForm) form;
        Becario b = (Becario) request.getSession().getAttribute(_BECARIO);
        CarreraHelper carreraHelper = new CarreraHelper(getSession(request));
        List<Carrera> cxb = carreraHelper.obtenerCarreras(b);
        System.out.println(cxb.size());
        request.setAttribute("carrerasList",cxb);
        ReporteNotasCarreraHelper helper = new ReporteNotasCarreraHelper(getSession(request));
        request.setAttribute("reporte", helper.construirReporteNotas(rnxc.getCodCarrera(),b));
        return mapping.findForward("success");
    }
}
